-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render snapshot for VM #190
Conversation
cc @miha-plesko |
b1d6c29
to
b4c74c4
Compare
@@ -134,13 +134,30 @@ def parse_vm(vm) | |||
} | |||
end | |||
|
|||
snapshot_resp = vm.service.get_snapshot_section(vm.id).data[:body][:Snapshot] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make a helper function to retrieve the snapshot
@@ -134,13 +134,30 @@ def parse_vm(vm) | |||
} | |||
end | |||
|
|||
snapshot_resp = vm.service.get_snapshot_section(vm.id).data[:body][:Snapshot] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use @connection
instead of vm.service
.
snapshot = [ | ||
{ | ||
:name => "#{vm.name}(snapshot)", | ||
:uid => "#{vm.id}-#{snapshot_resp[:created]}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked if the href
attribute could be used (or part thereof) for the uid
and ems_ref
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I have checked, href
only contains id of VM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a different seperator than '-'
since that is part of the uuid already? That way you can split the uid apart with something like snapshot.uid.split("__")
@@ -58,6 +58,18 @@ | |||
end | |||
end | |||
|
|||
it "will perform refresh for snapshot" do | |||
2.times do # Run twice to verify that a second run with existing data does not change anything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you separating this to have a different VCR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we talked about it with @miha-plesko and decided to create a new VCR.
b4c74c4
to
2ac1225
Compare
@@ -217,4 +218,24 @@ def parse_vapp_template(vapp_template) | |||
|
|||
return uid, new_result | |||
end | |||
|
|||
def parse_snapshot(vm) | |||
snapshot_resp = @connection.get_snapshot_section(vm.id).data[:body][:Snapshot] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use data.fetch_path(:body, :Snapshot)
here so we fail the refresh with an exception if body is somehow nil
snapshot = [ | ||
{ | ||
:name => "#{vm.name}(snapshot)", | ||
:uid => "#{vm.id}-#{snapshot_resp[:created]}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a different seperator than '-'
since that is part of the uuid already? That way you can split the uid apart with something like snapshot.uid.split("__")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sasoc some minor comments. To make the old VCR spec green again, please mock parse_snapshot
function there.
@@ -141,6 +141,7 @@ def parse_vm(vm) | |||
:name => name, | |||
:vendor => "vmware", | |||
:raw_power_state => status, | |||
:snapshots => parse_snapshot(vm), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:snapshots => [parse_snapshot(vm)].compact,
Nitpicking, but can you please use such format ^, it's annoying if we say "parse (single) snapshot" and then return a list :)
] | ||
end | ||
|
||
snapshot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could simplify the whole function:
resp = @connection.get_snapshot_section(vm.id).data
if (snapshot_resp = resp.fetch_path(:body, :Snapshot))
{
:name => "#{vm.name}(snapshot)",
:uid => "#{vm.id}-#{snapshot_resp[:created]}",
...
}
end
895e331
to
c975370
Compare
end | ||
|
||
snapshot | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def parse_snapshot(vm)
resp = @connection.get_snapshot_section(vm.id).data
if (snapshot_resp = resp.fetch_path(:body, :Snapshot))
{
:name => "#{vm.name} (snapshot)",
:uid => "#{vm.id}_#{snapshot_resp[:created]}",
:ems_ref => "#{vm.id}_#{snapshot_resp[:created]}",
:parent_id => vm.id,
:parent_uid => vm.id,
:create_time => snapshot_resp[:created],
:total_size => snapshot_resp[:size]
}
else
nil
end
end
@@ -40,6 +40,8 @@ | |||
end | |||
|
|||
it "will perform a full refresh" do | |||
allow_any_instance_of(ManageIQ::Providers::Vmware::CloudManager::RefreshParser).to receive(:parse_snapshot).and_return(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Mock snapshot collection since VCR cassete does not contain those request yet.
# TODO: record a new VCR cassette when provider development is done.
allow_any_instance_of(described_class).to receive(:parse_snapshot).and_return(nil)
87fe4cd
to
8d7f84b
Compare
9e84bcd
to
678825c
Compare
With this commit we support VM snapshot inventoring. Since vCloud is quite modes with information it reveals about VM snapshots (only creation time, size and poweredOn, which tells if if the virtual machine was powered on when the snapshot was created) we need to compose `uid` and `ems_ref` dynamically. Signed-off-by: Miha Pleško <miha.plesko@xlab.si> Signed-off-by: Sašo Cvitkovič <saso.cvitkovic@xlab.si>
678825c
to
a8eb345
Compare
Checked commit sasoc@a8eb345 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 **
|
@miq-bot add_label enhancement,gaprindashvili/yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 looks good, nice tests
Render snapshot for VM (cherry picked from commit 8b0d0e8) https://bugzilla.redhat.com/show_bug.cgi?id=1552686
Gaprindashvili backport details:
|
Sprint 70 update to changelog
Refresh parser now renders snapshot for VM.
VCloud only returns creation time, size and
poweredOn, which tells if if the virtual machine was
powered on when the snapshot was created. So
uid
andems_ref
are created from VM's id and creation timeof snapshot.
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1550906